package com.dtguai.app.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;

/**
 * @author guo
 * @date 2020年7月10日10:48:26
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Document(indexName = "cx-es-sb-1", shards = 10, replicas = 2)
public class Es {

    /**
     * id
     */
    @Id
    @Field(type = FieldType.Integer, index = false, store = true)
    private int id;

    /**
     * @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
     */
    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String name;


    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String msg;

    @Field(type = FieldType.Integer)
    private int age;

    /**
     * pattern = "dd.MM.yyyy hh:mm"
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Field(type = FieldType.Date, format = DateFormat.date_optional_time, store = true)
    private LocalDateTime createTime;

    @Override
    public String toString() {

        return "id:" + id + ",name:" + name + ",age:" + age + ",createTime:" + createTime;
    }
}